<?php
namespace app\admin\controller;
use think\Db;

class User extends Base
{
    /**
     * 添加账号
     */
    public function addUser()
    {
        $data = input();
        $tmp['account'] = $data['username'];
        $tmp['passwd'] = md5(md5($data['password']).config('keys'));
        $list = Db::name('account')->insert($tmp);
        if($list) {
            return $this->returnOk();
        }else {
            return $this->returnError('添加失败');
        }
    }

    /**
     * 修改账号1
     */
    public function selUser()
    {
        $data = input();
        $list = Db::name('account')->where('id',$data['nowId'])->find();
        if($list) {
            return ['status'=>1,'data'=>$list];
        }
    }

    /**
     * 修改账号2
     */
    public function modUser()
    {
        $data = input();
        //判断是否修改了密码
        if(empty($data['modpwd'])) {
            Db::name('account')->where('id',$data['nowId'])->update(['account'=>$data['moduser']]);
        }else {
            Db::name('account')->where('id',$data['nowId'])->update(['account'=>$data['moduser'],'passwd'=>md5(md5($data['modpwd']).config('keys'))]);
        }
        return ['status'=>1,'msg'=>'修改成功'];
    }

    /**
     * 删除账号
     */
    public function delUser()
    {
        $data = input();
        Db::name('account')->where('id',$data['nowId'])->update(['enable'=>1]);
        return ['status'=>1,'msg'=>'删除成功'];
    }
}